def read_names_from_file(file_path):
    """读取文件并返回名字列表"""
    with open(file_path, 'r', encoding='utf-8') as file:
        # 如果是全名单文件，直接读取每一行作为名字
        if "全名单" in file_path:
            names = [line.strip() for line in file.readlines()]
        # 如果是签到名单文件，需要提取并规范化名字
        else:
            sign_in_records = []
            for line in file.readlines()[1:]:  # 跳过标题行
                record = line.strip().split(',')
                name = record[0].split(':')[1].strip()  # 提取名字部分
                # 规范化名字，去除可能的学号前缀
                if 'f' in name and len(name.split('f')) > 1:
                    name = name.split('f')[-1].strip()
                elif ' ' in name and len(name.split(' ')) > 1:
                    parts = name.split(' ')
                    # 假设学号部分只包含数字和可能的短横线，而名字是中文
                    for part in reversed(parts):
                        if not part.replace('-', '', 1).isdigit():
                            name = part
                            break
                sign_in_records.append(name)
            names = sign_in_records
    return names


def find_absent_students(full_list_path, sign_in_path):
    """找出没有签到的人"""
    full_names = read_names_from_file(full_list_path)
    sign_in_names = set(read_names_from_file(sign_in_path))

    absent_students = [name for name in full_names if name not in sign_in_names]

    return absent_students


# 文件路径
full_list_path = 'C:/Users/12610/Desktop/卓越班-大三-全名单.txt'
sign_in_path = 'C:/Users/12610/Desktop/卓越班-大三-1115.txt'

# 找出没来的人
absent_students = find_absent_students(full_list_path, sign_in_path)

# 打印结果
print("没来的人有：")
for student in absent_students:
    print(student)